<?php
class Default_Plugin_AccessCheck extends Zend_Controller_Plugin_Abstract
{
	private $acl = null;
	private $auth = null;
	public function __construct(Zend_Acl $acl, Zend_Auth $auth)
	{
		$this->acl = $acl;
		//$acl->isAllowed()
		$this->auth = $auth;
		//	$auth->getIdentity()
	}
	public function preDispatch(Zend_Controller_Request_Abstract $request)
	{
	
		if ($this->auth->hasIdentity())
		{
			if ($this->auth->getIdentity()->id_group == 1)
			{
				$resource = $request->getControllerName();
				$action = $request->getActionName();
				if (!$this->acl->isAllowed($this->auth->getIdentity()->id_group,$resource,$action))
				{
					$request->setModuleName('default')->setControllerName('error')->setActionName('denied');
				}
			}
		}
		else
			$request->setModuleName('default')->setControllerName('error')->setActionName('denied');
	}
}